package vip.bblog.user.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.bblog.common.utils.BaseResult;
import vip.bblog.common.utils.valid.Default;
import vip.bblog.common.utils.valid.Update;
import vip.bblog.user.controller.base.BaseController;
import vip.bblog.user.entity.SystemUser;
import vip.bblog.user.service.SystemUserService;

/**
 * <p>
 * 系统（后台）用户表 前端控制器
 * </p>
 *
 * @author yuyong
 * @since 2019-04-28
 */
@RestController
@RequestMapping("/user/sys")
public class SystemUserController extends BaseController {

    @Autowired
    private SystemUserService systemUserService;

    @ApiOperation(value = "增加用户", notes = "增加用户")
    @PostMapping
    public BaseResult<Object> insert(@Validated(value = Default.class) @RequestBody SystemUser systemUser) {
        return systemUserService.insert(systemUser);
    }

    @ApiOperation(value = "根据id删除用户", notes = "根据id删除用户")
    @DeleteMapping("/{id}")
    public BaseResult<Object> deleteById(@PathVariable(value = "id") String id) {
        return systemUserService.deleteById(id);
    }

    @ApiOperation(value = "根据id更新用户信息", notes = "根据id更新用户信息")
    @PutMapping
    public boolean updateById(@Validated(value = Update.class) @RequestBody SystemUser systemUser) {
        return systemUserService.updateById(systemUser);
    }

    @ApiOperation(value = "模糊分页查询用户", notes = "模糊分页查询用户")
    @GetMapping
    public BaseResult<Object> selectPageByExample(Page<SystemUser> page, SystemUser systemUser) {
        return systemUserService.selectPageByExample(page, systemUser);
    }

    @ApiOperation(value = "根据id查询用户信息", notes = "根据id查询用户信息")
    @GetMapping("/{id}")
    public BaseResult<Object> select(@PathVariable(value = "id") String id) {
        return new BaseResult<>(systemUserService.getById(id));
    }

}
